import random

setGlobalDuration(-1)

example = 2

# example 1: receives OSC values from external device
if example == 1:
    fund = random.randint(500,1000)
    wav = genWaveform([1,0,.2,0,.05,0,.02,0,0,.01,0,0,.004])
    oscReceive(bus=['pit', 'amp'], address=['/pitch', '/amp'], port=7000, portamento=0.005)
    num = 10
    for i in range(num):
        rand = random.random() * 0.01 + 1
        pitch = fund * rand
        waveform(pitch=pitch, amplitude=.1, pitchVar='pit', amplitudeVar='amp', table=wav)
        square(pitch=pitch*0.5, amplitude=.1, pitchVar='pit', amplitudeVar='amp')

# example 2: sends OSC values to an external device
if example == 2:
    vibrato(bus='vib')
    randomi(bus='amp')
    oscSend(input=['vib', 'amp'], address=['/pitch', '/amplitude'], port=6000)
    
startCsound()